
;; Make a table.

(define T (make-table))

;; Table lookup returns #f for non-existant keys.

(table-get T -6)		; =| ERROR

(table-get* T -6)		; => #f

;; Table insertion.

(table-put! T -6 6)			;

(table-get* T -6)

;; Table deletion.

(table-remove! T -6)			;

;; Iteration

(table-for-each
 (lambda (key value)
   (inform "AT" key "IS" value))
 T)

;; There are insert! and lookup procedures to work with mutliple
;; dimensioned tables.  These are simple idioms that use the list of
;; keys as the key.

(mtable-put! T -5 -4 -3 543)

(table-get* T -5)		; => #f

(mtable-get* T -5 -4 -3)	; => (HASH-KEY . 543)

(mtable-get* T -5 -4 -3)	; => 543

(table-get* T '(-5 -4 -3))	; => 543

;; Tables are identifiable.

(table? T)				; => #t

(table? 6)				; => #f

;; A copy of a table holds the same objects, if they are mutable the
;; mutation will be shared.

(begin 
  (define a (make-table))
  (table-put! a 1 -1)
  (table-put! a 2 (list->string '(#\s #\t #\r #\i #\n #\g)))
  (define b (table-copy a))
  (table-put! b 1 'negative-one)
  (string-set! (table-get* b 2) 3 #\u)
  (list (table->alistL a) (table->list b)))

(let ((t (alistL->table '((a 1) (b 2) (c 3)))))
  (table-map (lambda (k v) (list k v)) t))

;; => (("strung" -1) ("strung" negative-one))
      
(table->alistL
 (alistL->table
  '((a 1) (b 2) (c 3))))

;; => ((b 2) (a 1) (c 3))
